//
// Created by zhupi on 2024/11/20.
//

#include "vdanced_dialog.h"
#include <QLabel>
#include <QLineEdit>
#include <QCheckBox>
#include <QGroupBox>
#include <QComboBox>
#include <QRadioButton>

namespace {
    const int LABEL_WIDTH = 300;
}

VdancedDialog::VdancedDialog(const QString &title, QWidget *parent)
{

}

void VdancedDialog::Init()
{
    this->resize(500, 700);
    QVBoxLayout *vbox = new QVBoxLayout;
    tabWidget_ = new QTabWidget(this);
    InitGeneral();
    InitOptions();
    InitAdvanced();
    vbox->addWidget(tabWidget_);
}

void VdancedDialog::InitGeneral()
{
    QWidget *widget = new QWidget;
    tabWidget_->addTab(widget, "General");
    QVBoxLayout *mainVbox = new QVBoxLayout;
    widget->setLayout(mainVbox);

    QHBoxLayout *hbox1 = new QHBoxLayout;
    QLabel *setNameLabel = new QLabel("Setup Name");
    setNameLabel->setFixedWidth(LABEL_WIDTH);
    QLineEdit *setUpName = new QLineEdit;

    hbox1->addWidget(setNameLabel);
    hbox1->addWidget(setUpName);
    mainVbox->addLayout(hbox1);

    QCheckBox *check = new QCheckBox("Enabled");

    hbox1->addWidget(check);
    InitAdaptive(mainVbox);
}


void VdancedDialog::InitAdaptive(QVBoxLayout *mainVbox)
{
    QGroupBox  *groupBox = new QGroupBox("Adaptive Solutions");
    QVBoxLayout *box = new QVBoxLayout;

    QHBoxLayout * hbox1 = new QHBoxLayout;
    QLabel *labelFre = new QLabel("Frequency");
    labelFre->setFixedWidth(LABEL_WIDTH);
    QLineEdit *freLabel = new QLineEdit;
    QComboBox *combox = new QComboBox;

    hbox1->addWidget(labelFre);
    hbox1->addWidget(freLabel);
    hbox1->addWidget(combox);
    hbox1->addStretch();
    box->addLayout(hbox1);

    QHBoxLayout * hbox2 = new QHBoxLayout;
    QLabel *maxLabel = new QLabel("Frequency");
    QLineEdit *maxEdit = new QLineEdit;
    maxLabel->setFixedWidth(LABEL_WIDTH);
    hbox2->addWidget(maxLabel);
    hbox2->addWidget(maxEdit);
    box->addLayout(hbox2);

    QHBoxLayout * hbox3 = new QHBoxLayout;
    QLabel *detailLabel = new QLabel("Frequency");
    QLineEdit *detailEdit = new QLineEdit;
    detailLabel->setFixedWidth(LABEL_WIDTH);
    hbox3->addWidget(detailLabel);
    hbox3->addWidget(detailEdit);
    box->addLayout(hbox3);

    groupBox->setLayout(box);
    mainVbox->addWidget(groupBox);
}

void VdancedDialog::InitOptions()
{
    QWidget *widget = new QWidget;
    tabWidget_->addTab(widget, "Options");
    QVBoxLayout *mainVbox = new QVBoxLayout;
    widget->setLayout(mainVbox);

    InitMesh(mainVbox);
    InitAdaptiveOtion(mainVbox);
    InitSolution(mainVbox);

}

void VdancedDialog::InitMesh(QVBoxLayout *mainVbox)
{
    QGroupBox *groupBox = new QGroupBox("Initial Mesh Option");
    mainVbox->addWidget(groupBox);

    QVBoxLayout *vbox = new QVBoxLayout;
    groupBox->setLayout(vbox);

    QCheckBox *checkBox = new QCheckBox("Do Lambda Refinement");
    vbox->addWidget(checkBox);

    QHBoxLayout *hbox = new QHBoxLayout;
    QLabel *labelLambad = new QLabel("Lambda");
    QLineEdit *edit = new QLineEdit;
    QCheckBox *checkDefaultValue = new QCheckBox("Use Default Value");
    hbox->addWidget(labelLambad);
    hbox->addWidget(edit);
    hbox->addWidget(checkDefaultValue);
    vbox->addLayout(hbox);

    QCheckBox *useFreeBox = new QCheckBox;
    vbox->addWidget(useFreeBox);
}

void VdancedDialog::InitAdaptiveOtion(QVBoxLayout *mainVbox)
{
    QGroupBox *groupBox = new QGroupBox("Adaptive Options");
    mainVbox->addWidget(groupBox);

    QVBoxLayout *vbox = new QVBoxLayout;
    groupBox->setLayout(vbox);

    QHBoxLayout *hbox1 = new QHBoxLayout;
    QLabel *maximumRef = new QLabel("Maximum Refinement Per Pass");
    hbox1->addWidget(maximumRef);
    vbox->addLayout(hbox1);

    QHBoxLayout *hbox2 = new QHBoxLayout;
    QCheckBox * maximuRef = new QCheckBox("Maximum Refinement");
    hbox2->addWidget(maximuRef);
    vbox->addLayout(hbox2);

    QHBoxLayout *hbox3 = new QHBoxLayout;
    QLabel *MinimumNumberOfPasses = new QLabel("Minimum Number Of Passes");
    hbox3->addWidget(MinimumNumberOfPasses);
    vbox->addLayout(hbox3);

    QHBoxLayout *hbox4 = new QHBoxLayout;
    QLabel *MinimumConvergedPasses = new QLabel("Minimum Converged Passes");
    hbox4->addWidget(MinimumConvergedPasses);
    vbox->addLayout(hbox4);
}

void VdancedDialog::InitSolution(QVBoxLayout *mainVbox)
{
    QGroupBox *groupBox = new QGroupBox("Solution Options");
    mainVbox->addWidget(groupBox);

    QVBoxLayout *vbox = new QVBoxLayout;
    groupBox->setLayout(vbox);

    QHBoxLayout *hbox1 = new QHBoxLayout;
    QLabel *orderOfBasis = new QLabel("Maximum Refinement Per Pass");
    hbox1->addWidget(orderOfBasis);
    vbox->addLayout(hbox1);

    QHBoxLayout *hbox2 = new QHBoxLayout;
    QRadioButton *directbutton = new QRadioButton("Direct Solver");
    hbox2->addWidget(directbutton);
    vbox->addLayout(hbox2);

    QHBoxLayout *hbox3 = new QHBoxLayout;
    QRadioButton *iterativeSolverButton = new QRadioButton("Iterative Solver");
    hbox3->addWidget(iterativeSolverButton);
    vbox->addLayout(hbox3);
}

void VdancedDialog::InitAdvanced()
{
    QWidget *widget = new QWidget;
    tabWidget_->addTab(widget, "Advanced");
    QVBoxLayout *mainVbox = new QVBoxLayout;
    widget->setLayout(mainVbox);
}
